<template>
	<view class="body">
		<u-navbar :border-bottom='false' title-color='#040303' back-icon-color='#040303' background="" title="心率变异性报告"
			:is-fixed='false'></u-navbar>
		<view class="content">
			<view class="table">
				<view class="title">
					时域与频域分析指标
				</view>
				<view style="padding: 10rpx;background-color: #fff;">
					<u-table border-color='#fff'>
						<u-tr>
							<u-th width='66%'>时域指标</u-th>
							<u-th>时域参考值</u-th>
						</u-tr>
						<u-tr>
							<u-td>NNVGR</u-td>
							<u-td>
								<u-icon v-if="nnvgr > 1000" style="margin: auto;" :label='nnvgr' label-pos='left'
									name="arrow-upward" color="#ff2727" size="28"></u-icon>
								<u-icon v-else-if="nnvgr < 600" style="margin: auto;" :label='nnvgr' label-pos='left'
									name="arrow-downward" color="#ff2727" size="28"></u-icon>
								<u-icon v-else style="margin: auto;" :label='nnvgr' label-pos='left'
									name="checkbox-mark" color="#0dd30c" size="28"></u-icon>
							</u-td>
							<u-td>600-1000</u-td>
						</u-tr>
						<u-tr>
							<u-td>SDNN</u-td>
							<u-td>
								<u-icon v-if="HRVreport.hrvTDResult.sdnn.toFixed(0) > 122" style="margin: auto;"
									:label='HRVreport.hrvTDResult.sdnn.toFixed(0)' label-pos='left' name="arrow-upward"
									color="#ff2727" size="28"></u-icon>
								<u-icon v-else-if="HRVreport.hrvTDResult.sdnn.toFixed(0) < 16" style="margin: auto;"
									:label='HRVreport.hrvTDResult.sdnn.toFixed(0)' label-pos='left'
									name="arrow-downward" color="#ff2727" size="28"></u-icon>
								<u-icon v-else style="margin: auto;" :label='HRVreport.hrvTDResult.sdnn.toFixed(0)'
									label-pos='left' name="checkbox-mark" color="#0dd30c" size="28"></u-icon>
							</u-td>
							<u-td>16-122</u-td>
						</u-tr>
						<u-tr>
							<u-td>rMSDD</u-td>
							<u-td>
								<u-icon v-if="HRVreport.hrvTDResult.rmssd.toFixed(2) > 67" style="margin: auto;"
									:label='HRVreport.hrvTDResult.rmssd.toFixed(2)' label-pos='left' name="arrow-upward"
									color="#ff2727" size="28"></u-icon>
								<u-icon v-else-if="HRVreport.hrvTDResult.rmssd.toFixed(2) < 9.34" style="margin: auto;"
									:label='HRVreport.hrvTDResult.rmssd.toFixed(2)' label-pos='left'
									name="arrow-downward" color="#ff2727" size="28"></u-icon>
								<u-icon v-else style="margin: auto;" :label='HRVreport.hrvTDResult.rmssd.toFixed(2)'
									label-pos='left' name="checkbox-mark" color="#0dd30c" size="28"></u-icon>
							</u-td>
							<u-td>9.34-67</u-td>
						</u-tr>
						<u-tr>
							<u-td>SDSD</u-td>
							<u-td>
								<u-icon v-if="HRVreport.hrvTDResult.sdsd.toFixed(2) > 67" style="margin: auto;"
									:label='HRVreport.hrvTDResult.sdsd.toFixed(2)' label-pos='left' name="arrow-upward"
									color="#ff2727" size="28"></u-icon>
								<u-icon v-else-if="HRVreport.hrvTDResult.sdsd.toFixed(2) < 9.34" style="margin: auto;"
									:label='HRVreport.hrvTDResult.sdsd.toFixed(2)' label-pos='left'
									name="arrow-downward" color="#ff2727" size="28"></u-icon>
								<u-icon v-else style="margin: auto;" :label='HRVreport.hrvTDResult.sdsd.toFixed(2)'
									label-pos='left' name="checkbox-mark" color="#0dd30c" size="28"></u-icon>
							</u-td>
							<u-td>9.34-67</u-td>
						</u-tr>
						<u-tr>
							<u-td>NN50</u-td>
							<u-td>
								<u-icon v-if="HRVreport.hrvTDResult.nn50.toFixed(0) > 125" style="margin: auto;"
									:label='HRVreport.hrvTDResult.nn50.toFixed(0)' label-pos='left' name="arrow-upward"
									color="#ff2727" size="28"></u-icon>
								<u-icon v-else-if="HRVreport.hrvTDResult.nn50.toFixed(0) < 1" style="margin: auto;"
									:label='HRVreport.hrvTDResult.nn50.toFixed(0)' label-pos='left'
									name="arrow-downward" color="#ff2727" size="28"></u-icon>
								<u-icon v-else style="margin: auto;" :label='HRVreport.hrvTDResult.nn50.toFixed(0)'
									label-pos='left' name="checkbox-mark" color="#0dd30c" size="28"></u-icon></u-td>
							<u-td>1-125</u-td>
						</u-tr>
						<u-tr>
							<u-td>PNN50(%)</u-td>
							<u-td>
								<u-icon v-if="HRVreport.hrvTDResult.pnn50.toFixed(2) > 42.75" style="margin: auto;"
									:label='HRVreport.hrvTDResult.pnn50.toFixed(2)' label-pos='left' name="arrow-upward"
									color="#ff2727" size="28"></u-icon>
								<u-icon v-else-if="HRVreport.hrvTDResult.pnn50.toFixed(2) < 0.23" style="margin: auto;"
									:label='HRVreport.hrvTDResult.pnn50.toFixed(2)' label-pos='left'
									name="arrow-downward" color="#ff2727" size="28"></u-icon>
								<u-icon v-else style="margin: auto;" :label='HRVreport.hrvTDResult.pnn50.toFixed(2)'
									label-pos='left' name="checkbox-mark" color="#0dd30c" size="28"></u-icon>
							</u-td>
							<u-td>0.23-42.75</u-td>
						</u-tr>
					</u-table>
				</view>

			</view>
			<view class="table">
				<view style="padding: 10rpx;background-color: #fff;">
					<u-table border-color='#fff'>
						<u-tr>
							<u-td>TP</u-td>
							<u-td>
								<u-icon v-if="tp > 6680" style="margin: auto;" :label='tp' label-pos='left'
									name="arrow-upward" color="#ff2727" size="28"></u-icon>
								<u-icon v-else-if="tp < 156" style="margin: auto;" :label='tp' label-pos='left'
									name="arrow-downward" color="#ff2727" size="28"></u-icon>
								<u-icon v-else style="margin: auto;" :label='tp' label-pos='left' name="checkbox-mark"
									color="#0dd30c" size="28"></u-icon>
							</u-td>
							<u-td>156-6680</u-td>
						</u-tr>
						<u-tr>
							<u-td>VLF</u-td>
							<u-td>
								<u-icon v-if="HRVreport.hrvFDResult.vlf.toFixed(2) > 6459" style="margin: auto;"
									:label='HRVreport.hrvFDResult.vlf.toFixed(2)' label-pos='left' name="arrow-upward"
									color="#ff2727" size="28"></u-icon>
								<u-icon v-else-if="HRVreport.hrvFDResult.vlf.toFixed(2) < 74" style="margin: auto;"
									:label='HRVreport.hrvFDResult.vlf.toFixed(2)' label-pos='left' name="arrow-downward"
									color="#ff2727" size="28"></u-icon>
								<u-icon v-else style="margin: auto;" :label='HRVreport.hrvFDResult.vlf.toFixed(2)'
									label-pos='left' name="checkbox-mark" color="#0dd30c" size="28"></u-icon>
							</u-td>
							<u-td>74-6459</u-td>
						</u-tr>
						<u-tr>
							<u-td>LF</u-td>
							<u-td>
								<u-icon v-if="HRVreport.hrvFDResult.lf.toFixed(2) > 1720" style="margin: auto;"
									:label='HRVreport.hrvFDResult.lf.toFixed(2)' label-pos='left' name="arrow-upward"
									color="#ff2727" size="28"></u-icon>
								<u-icon v-else-if="HRVreport.hrvFDResult.lf.toFixed(2) < 18" style="margin: auto;"
									:label='HRVreport.hrvFDResult.lf.toFixed(2)' label-pos='left' name="arrow-downward"
									color="#ff2727" size="28"></u-icon>
								<u-icon v-else style="margin: auto;" :label='HRVreport.hrvFDResult.lf.toFixed(2)'
									label-pos='left' name="checkbox-mark" color="#0dd30c" size="28"></u-icon>
							</u-td>
							<u-td>18-1720</u-td>
						</u-tr>
						<u-tr>
							<u-td>HF</u-td>
							<u-td>
								<u-icon v-if="HRVreport.hrvFDResult.hf.toFixed(2) > 1690" style="margin: auto;"
									:label='HRVreport.hrvFDResult.hf.toFixed(2)' label-pos='left' name="arrow-upward"
									color="#ff2727" size="28"></u-icon>
								<u-icon v-else-if="HRVreport.hrvFDResult.hf.toFixed(2) < 10" style="margin: auto;"
									:label='HRVreport.hrvFDResult.hf.toFixed(2)' label-pos='left' name="arrow-downward"
									color="#ff2727" size="28"></u-icon>
								<u-icon v-else style="margin: auto;" :label='HRVreport.hrvFDResult.hf.toFixed(2)'
									label-pos='left' name="checkbox-mark" color="#0dd30c" size="28"></u-icon>
							</u-td>
							<u-td>10-1690</u-td>
						</u-tr>
						<u-tr>
							<u-td>LF/HF</u-td>
							<u-td>
								<u-icon v-if="HRVreport.hrvFDResult.lfDhf.toFixed(2) > 16.64" style="margin: auto;"
									:label='HRVreport.hrvFDResult.lfDhf.toFixed(2)' label-pos='left' name="arrow-upward"
									color="#ff2727" size="28"></u-icon>
								<u-icon v-else-if="HRVreport.hrvFDResult.lfDhf.toFixed(2) < 0.14" style="margin: auto;"
									:label='HRVreport.hrvFDResult.lfDhf.toFixed(2)' label-pos='left'
									name="arrow-downward" color="#ff2727" size="28"></u-icon>
								<u-icon v-else style="margin: auto;" :label='HRVreport.hrvFDResult.lfDhf.toFixed(2)'
									label-pos='left' name="checkbox-mark" color="#0dd30c" size="28"></u-icon></u-td>
							<u-td>0.14-16.64</u-td>
						</u-tr>
						<u-tr>
							<u-td>VLF/HF</u-td>
							<u-td>
								<u-icon style="margin: auto;" :label='HRVreport.hrvFDResult.vlfDhf.toFixed(2)'
									label-pos='left' name="question" color="#ffae00" size="28"></u-icon>
							</u-td>
							<u-td>...</u-td>
						</u-tr>
					</u-table>
				</view>
			</view>

			<view class="table">
				<view style="padding: 10rpx;background-color: #fff;">
					<view
						style="background-color: #eeeeee;border-radius: 10rpx; text-align: center;line-height: 64rpx;">
						散点图</view>
					<view style="font-size: 24rpx;">*正常人的Poincare数点图呈头小体长尾大的彗星状、鱼雷状</view>
					<lechart ref="echarts2"></lechart>
					<view style="display: flex;">
						<view class="SD">
							<view class="name">
								SD1
							</view>
							<view class="num">
								{{HRVreport.poincareInfoDTO.SD1.toFixed(2)}}
							</view>
						</view>
						<view class="SD">
							<view class="name">
								SD2
							</view>
							<view class="num">
								{{HRVreport.poincareInfoDTO.SD2.toFixed(2)}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view style="font-size: 24rpx;">注：心率变异性(HRV)是衡量心跳间隔变化的指标反映了自主神经系统的健康状况。高HRV通常代表身体健康，而低HRV可能与压力、疲劳或疾病相关。</view>
		<view style="font-size: 24rpx;text-align: center;color: #929292;margin: 30rpx 0;">（数据仅供参考，如有不适，请及时就医。）</view>
		</view>
		<u-toast ref="uToast1" />
	</view>
</template>

<script>
	import lechart from "@/pages/chart/components/lime-echart/components/l-echart/l-echart.vue";
	import * as echarts from '../components/echarts.esm.min.js'
	import {
		getSceneType,
		postScenenotify,
		getScenenotify,
		putScene,
		getPropert,
		getdeviceSet
	} from "@/api/device/index.js";
	import {
		getCurrentPage
	} from '@/core/app'
	import StorageUtils from "@/utils/StorageUtils";
	export default {
		components: {
			lechart,
		},
		data() {
			return {
				deviceId: 2051,
				DeviceName: 'B8:3D:FB:E0:9A:C9',
				deviceInfo: {}, //设备信息
				HRVreport: JSON.parse(JSON.parse(StorageUtils.get('HRVreport')).reportContent),
				nnvgr: 0,
				tp: 0,
			}
		},
		onReady() {
			const sum = this.HRVreport.rrs.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
			// 计算平均数
			const average = sum / this.HRVreport.rrs.length;
			this.nnvgr = average.toFixed(0);
			this.tp = ((this.HRVreport.hrvFDResult.vlf + this.HRVreport.hrvFDResult.lf + this.HRVreport.hrvFDResult.hf) /
				3).toFixed(2)
			let arr = this.HRVreport.rrs;
			let max = Math.max(...arr)
			const result = [];
			for (let i = 0; i < arr.length - 1; i++) {
				result.push([arr[i], arr[i + 1]]);
			}
			let option = {
				xAxis: {
				},
				yAxis: {
				},
				grid: {
					left: '0%',
					right: '6%',
					top: '4%',
					bottom: '4%',
					containLabel: true
				},
				series: [{
					symbolSize: 5,
					data: result,
					type: 'scatter'
				}]
			};

			this.$refs.echarts2.init(echarts, chart => {
				chart.setOption(option);
			});
		},
		onHide() {
			// if (this.mqttPing) {
			// 	clearInterval(this.mqttPing);
			// 	this.simDevice.close();
			// }
		},
		methods: {}
	}
</script>

<style lang="scss">
	page {
		background-color: #f2f3f5;
	}

	.uni-picker-container {
		z-index: 999999 !important;
	}

	.body {
		// padding: 0 0 0;
		color: #040303;
		background: linear-gradient(to bottom, #85f9e5, #f2f3f5) 0 0 / 100% 500rpx no-repeat;
		.SD{
			display: flex;
			width: 35%;
			margin: 30rpx 0 30rpx 10%;
			border: 1px solid #0c0c0c;
			.name{
				width: 50%;
				background-color: #dadade;
				line-height: 80rpx;
				text-align: center;
				font-size: 24rpx
			}
			.num{
				width: 50%;
				background-color: #fff;
				line-height: 80rpx;
				text-align: center;
				font-size: 24rpx
			}
		}
		.content {
			padding: 20rpx 20rpx 20rpx 20rpx;

			.table {
				margin-bottom: 20rpx;
				border-radius: 20rpx;

				.title {
					background: linear-gradient(18deg, #aaeed7, #7ce1a2);
					height: 76rpx;
					font-size: 36rpx;
					text-align: center;
					border-radius: 10rpx 10rpx 0 0;
					line-height: 76rpx;
				}
			}
		}
	}
</style>